/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.display;

import plash.geom.Point;
import plash.utils.Logger;

/**
 *
 * @author  #0K Srinivasan <hashok.com>
 */
public class GraphicTriangle extends GraphicLinearPathShape
{
    private int _x1;
    private int _y1;
    private int _x2;
    private int _y2;
    private int _x3;
    private int _y3;

    public GraphicTriangle(Graphics g, int x1, int y1, int x2, int y2, int x3, int y3)
    {
        super(g);

        _x1 = x1;
        _y1 = y1;

        _x2 = x2;
        _y2 = y2;

        _x3 = x3;
        _y3 = y3;

        __minPoint.setX(Math.min(x1, x2));
        __minPoint.setX(Math.min(__minPoint.getX(), x3));

        __minPoint.setY(Math.min(y1, y2));
        __minPoint.setY(Math.min(__minPoint.getY(), y3));
        
        __maxPoint.setX(Math.max(x1, x2));
        __maxPoint.setX(Math.max(__maxPoint.getX(), x3));

        __maxPoint.setY(Math.max(y1, y2));
        __maxPoint.setY(Math.max(__maxPoint.getY(), y3));

        __boundingBox.setX(__minPoint.getX());
        __boundingBox.setY(__minPoint.getY());

        __boundingBox.setWidth(__maxPoint.getX() - __minPoint.getX());
        __boundingBox.setHeight(__maxPoint.getY() - __minPoint.getY());
        
        Logger.log(__boundingBox);
    }

    public GraphicTriangle(Graphics g, Point p1, Point p2, Point p3)
    {
        this(g, p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY());
    }

    @Override
    public void execute()
    {
        if (__g == null)
        {
            return;
        }
        if (__g.getOwner().getPainter() == null)
        {
            return;
        }
        __g.getOwner().getPainter().triangle(_x1, _y1, _x2, _y2, _x3, _y3);
    }
}
